package com.michaelbulava.TFS.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcsUtil.VcsUtil;
import com.michaelbulava.TFS.vcs.TFSVcs;
import com.michaelbulava.TFS.vcs.utils.TFSFileUtil;

import java.util.Arrays;
import java.util.List;

/**
 * Created by MichaelA on 8/20/2015.
 */
public abstract class OnlineRequiredAction extends AnAction implements DumbAware {


    @Override
    public void update(AnActionEvent e){
        Project project = (Project)e.getData(CommonDataKeys.PROJECT);
        VirtualFile[] files = VcsUtil.getVirtualFiles(e);
        e.getPresentation().setEnabled(isOnline(project, files));
    }

    protected boolean isOnline(Project project, VirtualFile[] files){
        TFSVcs vcs = TFSVcs.getInstance(project);
        for(VirtualFile file : files){
            if (!vcs.isModuleOnline(file))
                return false;
        }
        return true;
    }
}
